home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / utils1 / fip09.arj / SOURCE.ZIP / CMDL_ARG.CPP < prev    next >
C/C++ Source or Header  |  1993-11-17  |  5KB  |  136 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module cmdl_arg.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/c/fips/source/cpp/RCS/cmdl_arg.cpp 0.9.1.1 1993/11/17 17:51:03 schaefer Exp schaefer $
  8.  
  9.     Copyright (C) 1993 Arno Schaefer
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26.     Report problems and direct all questions to:
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de
  29. */
  30.  
  31. #include <stdio.h>
  32. #include <ctype.h>
  33. #include <string.h>
  34. #include <stdlib.h>
  35. #include "global.h"
  36.  
  37. /* ----------------------------------------------------------------------- */
  38. /* Replacement for atoi                                                    */
  39. /* ----------------------------------------------------------------------- */
  40.  
  41. static int atoint (char *string)
  42. {
  43.     long int value = 0;
  44.     while (isdigit (*string))
  45.     {
  46.         value = value * 10 + (*string - '0');
  47.         if (value > 32767) return (-1);
  48.         string++;
  49.     }
  50.     if (*string != '\0') return (-1);
  51.     return (int) value;
  52. }
  53.  
  54. /* ----------------------------------------------------------------------- */
  55. /* Usage instructions                                                      */
  56. /* ----------------------------------------------------------------------- */
  57.  
  58. static void usage (void)
  59. {
  60.     printf ("\nFIPS {[-q][-t][-d][-h|-?][-d<num>][-p<num>][-c<num>][-s<+/->][-o<error>]}:\n\n");
  61.     printf ("-q        : quiet mode\n");
  62.     printf ("-t        : test mode (no writes to disk)\n");
  63.     printf ("-d        : debug mode\n");
  64.     printf ("-h/-?     : this help page\n");
  65.     printf ("-d<num>   : select drive <num>\n");
  66.     printf ("-p<num>   : select partition <num>\n");
  67.     printf ("-c<num>   : new start cylinder = <num>\n");
  68.     printf ("-s<+/->   : save rootsector and bootsector to floppy\n");
  69.     printf ("-o<error> : override error message\n\n");
  70.     printf ("where <error> is\n\n");
  71.     printf ("mb - more than one bootable partition\t");
  72.     printf ("bf - invalid bootable-flag\n");
  73.     printf ("lf - FAT too large\t\t\t");
  74.     printf ("sf - FAT too small\n");
  75.     printf ("md - wrong media descriptor byte\t");
  76.     printf ("re - rootdir entries not multiple of 16\n");
  77. }
  78.  
  79. /* ----------------------------------------------------------------------- */
  80. /* Process commandline parameters                                          */
  81. /* ----------------------------------------------------------------------- */
  82.  
  83. void evaluate_argument_vector (int argc,char *argv[])
  84. {
  85.     while (--argc > 0)
  86.     {
  87.         int switchar = (*++argv)[0];
  88.         char *sw = *argv + 1;
  89.  
  90.         if (switchar != '/' && switchar != '-') error ("Invalid Commandline Parameter: %s",*argv);
  91.  
  92.         if (!strcmp (sw,"q") || !strcmp (sw,"quiet")) global.quiet_mode = true;
  93.         else if (!strcmp (sw,"t") || !strcmp (sw,"test")) global.test_mode = true;
  94.         else if (!strcmp (sw,"d") || !strcmp (sw,"debug")) global.debug_mode = true;
  95.         else if (!strcmp (sw,"s+")) global.ask_if_backup = false;
  96.         else if (!strcmp (sw,"s-"))
  97.         {
  98.             global.ask_if_backup = false;
  99.             global.backup_root = false;
  100.         }
  101.         else if (!strcmp (sw,"h") || !strcmp (sw,"help") || !strcmp (sw,"?"))
  102.         {
  103.             usage ();
  104.             exit (0);
  105.         }
  106.         else if (!strcmp (sw,"omb")) global.override_multiple_boot = true;
  107.         else if (!strcmp (sw,"obf")) global.override_bootable_flag = true;
  108.         else if (!strcmp (sw,"ore")) global.override_rootdir_entries = true;
  109.         else if (!strcmp (sw,"olf")) global.override_large_fat = true;
  110.         else if (!strcmp (sw,"osf")) global.override_small_fat = true;
  111.         else if (!strcmp (sw,"omd")) global.override_media_descriptor = true;
  112.  
  113.         else switch ((*argv)[1])
  114.         {
  115.             case 'd':
  116.             {
  117.                 if ((global.drive_number_cmdline = atoint (*argv + 2)) == -1) error ("Invalid Argument: %s",*argv);
  118.                 if ((global.drive_number_cmdline < 0x80) || (global.drive_number_cmdline > 0xff)) error ("Invalid Drive number: %d",global.drive_number_cmdline);
  119.                 break;
  120.             }
  121.             case 'p':
  122.             {
  123.                 if ((global.partition_number_cmdline = atoint (*argv + 2)) == -1) error ("Invalid Argument: %s",*argv);
  124.                 if ((global.partition_number_cmdline < 1) || (global.partition_number_cmdline > 4)) error ("Invalid Partition number: %d",global.partition_number_cmdline);
  125.                 break;
  126.             }
  127.             case 'c':
  128.             {
  129.                 if ((global.new_start_cylinder_cmdline = atoint (*argv + 2)) == -1) error ("Invalid Argument: %s",*argv);
  130.                 break;
  131.             }
  132.             default: error ("Invalid Commandline Parameter: %s",*argv);
  133.         }
  134.     }
  135. }
  136.